/**
* TG_Coder: Dzlua
* Email: 505544956@qq.com
* Time: 2017/05/10
*/
#pragma once

#include "common/common.h"

#define DEFAULT_URL "chrome://theme/current-channel-logo@1x"

namespace parser {

class TGLoginData {
public:
	std::string	name;
	std::string	platform;
	std::string	url;
	std::string	username;
	std::string	pwd;		
	std::string	pagenote;
	float		gamespeed;
	bool		isAutoLogin;
	int			loginnum;
public:
	TGLoginData() {
		gamespeed = 1.0;
		isAutoLogin = true;
		loginnum = 0;
	}
};

class TGIniData {
public:
	std::string		m_group;
	std::map<std::string, std::string> m_data;
	std::vector<std::string>				m_keyArr;
public:
	TGIniData();
	TGIniData(std::string m_group, std::string m_key, std::string m_value);
	void Parse(std::string m_text);
	int	GetSize();
	void Add(std::string m_key, std::string m_value);
	bool IsExists(std::string m_key);
	void Del(std::string m_key);
	std::string GetValue(std::string m_key);
	std::string  ToString();
};

class TGIniParse {
public:
	std::vector<TGIniData>   m_data;
public:
	void Parse(std::string m_text);
	std::string  ToString();
	bool GetGroupData(std::string m_group, std::vector<TGIniData>& m_arr);
	bool GetGroupData2(std::string m_group, std::vector<TGIniData>& m_arr);
	std::vector<std::string> GetValues(std::string m_group, std::string m_key, bool isfirst = FALSE);
	bool GetValue(std::string m_group, std::string m_key, std::string& m_value);
};

typedef std::vector<TGLoginData*> VData;
VData* ParserDataFile(std::string path);
bool WriteData2File(std::string path, VData* vdata, bool autoRelease = true);
bool WriteData2File(std::string path, const std::string& file);
void ReleaseVData(VData* vdata);

} // end namespace parser